import request from '@/utils/request'
import {useEncryptByMd5} from "@/utils/useEncryptByMd5"

// 登录方法
export function login(username, password, code, uuid) {
  const data = {
    loginCode: username,
    loginPassword: useEncryptByMd5("WenWuCaiShenDaoWoJia" + password),
    code,
    uuid
  }
  window.localStorage.setItem("username", encodeURI(username))
  return request({
    url: '/account/login',
    method: 'post',
    data: data
  })
}

// 注册方法
export function register(data) {
  return request({
    url: '/register',
    method: 'post',
    data: data
  })
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: '/public/user/getUserInfo',
    method: 'get'
  })
}

// 退出方法
export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: '/captchaImage',
    headers: {
      isToken: false
    },
    method: 'get',
    timeout: 20000
  })
}
// 首次重置密码
export function resetPwd(password,passwordAgain){
  const data={
    loginPassword:useEncryptByMd5("WenWuCaiShenDaoWoJia" + password),
    loginPasswordAgain:useEncryptByMd5("WenWuCaiShenDaoWoJia" + passwordAgain)
  }
  return request({
    url: '/public/user/resetPassword',
    method: 'post',
    data
  })
}
// 修改密码
export function updatePwd(lodPassword,password,passwordAgain) {
  const data={
    loginPassword: useEncryptByMd5("WenWuCaiShenDaoWoJia" + password),
    loginPasswordAgain: useEncryptByMd5("WenWuCaiShenDaoWoJia" + passwordAgain),
    oldLoginPassword: useEncryptByMd5("WenWuCaiShenDaoWoJia" + lodPassword)
  }
  return request({
    url: '/public/user/updatePassword',
    method: 'post',
    data
  })
}
